from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base

from conf.mysql_cnx import MysqlCnxPool
from pydantic import BaseModel

Base = declarative_base()


class User(Base):
    __tablename__ = 'user'
    id = Column(Integer, primary_key=True)

    username = Column(String)
    password = Column(String)


class UserModel(BaseModel):
    id: int
    username: str


def find_user(username: str):
    user = MysqlCnxPool().get_session().query(User) \
        .filter(User.username == username).first()
    return user
